package scrum.gui.Employee;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.WindowEvent;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFormattedTextField;

import scrum.entity.UserStory;


public class EmployeeDialog extends JDialog {
    
   
	private static final long serialVersionUID = 1L;
	
	private EmployeePane employeePane;
	int mode;
	
	public EmployeeDialog(EmployeePane employeePane,boolean modal,int mode) {
		
		this.employeePane = employeePane;
		this.mode = mode;
        initComponents();
    }
    
   
  
    private void initComponents() {
    	
        GridBagConstraints gridBagConstraints;
        btnSave = new JButton();
        btnClose = new JButton();
        
        
        jLabelName = new javax.swing.JLabel();
		jLabelRole = new javax.swing.JLabel();
		jLabelStartDate = new javax.swing.JLabel();
		jLabelDueDate = new javax.swing.JLabel();
		jLabelProgress = new javax.swing.JLabel();
		jTextFieldRole = new javax.swing.JTextField();
		jTextFieldName = new javax.swing.JTextField();
		jTextFieldProgress = new javax.swing.JTextField();
		dateFormat = new SimpleDateFormat("dd-MM-yyyy");
		dateFormat.setLenient(true);
		startDate = new javax.swing.JFormattedTextField(dateFormat);
		dueDate = new javax.swing.JFormattedTextField(dateFormat);
        getContentPane().setLayout(new GridBagLayout());

        setTitle("Employees");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });
        
		gridBagConstraints = new java.awt.GridBagConstraints();
		
		jLabelName.setText("Name");
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.weightx = 0;
		 getContentPane().add(jLabelName,gridBagConstraints);

		
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 0;
		gridBagConstraints.weightx = 1;
		 getContentPane().add(jTextFieldName, gridBagConstraints);
		
		
		
		
		jLabelRole.setText("Role");
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 1;
		gridBagConstraints.weightx = 0;
		 getContentPane().add(jLabelRole, gridBagConstraints);

		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 1;
		gridBagConstraints.weightx = 1;
		 getContentPane().add(jTextFieldRole, gridBagConstraints);
		
		jLabelStartDate.setText("StartDate");
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 2;
		gridBagConstraints.weightx = 0;
		 getContentPane().add(jLabelStartDate, gridBagConstraints);

		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 2;
		gridBagConstraints.weightx = 1;
		 getContentPane().add(startDate, gridBagConstraints);
		
		
		
		jLabelDueDate.setText("DueDate");
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 3;
		gridBagConstraints.weightx = 0;
		 getContentPane().add(jLabelDueDate, gridBagConstraints);

		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 3;
		gridBagConstraints.weightx = 1;
		 getContentPane().add(dueDate, gridBagConstraints);
		

		jLabelProgress.setText("Progress");
		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 4;
		gridBagConstraints.weightx = 0;
		 getContentPane().add(jLabelProgress, gridBagConstraints);

		gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 4;
		gridBagConstraints.weightx = 1;
		getContentPane().add(jTextFieldProgress, gridBagConstraints);

        btnSave.setText("Ok");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.gridx = 0;
		gridBagConstraints.gridy = 5;
		gridBagConstraints.weightx = 1;
        getContentPane().add(btnSave, gridBagConstraints);

        btnClose.setText("Close");
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
		gridBagConstraints.gridx = 1;
		gridBagConstraints.gridy = 5;
		gridBagConstraints.weightx = 1;
        getContentPane().add(btnClose, gridBagConstraints);
        
        if(mode == 2){
        	
        	
        }

        pack();
        setSize(300, 200);
    }
    
    private void setStory(UserStory userStory){
    	
    	this.jTextFieldName.setText(userStory.getResponsible());
    	this.jTextFieldProgress.setText(userStory.getBusinessValue());
    	this.jTextFieldRole.setText(String.valueOf(userStory.getProgress()));
    	this.startDate.setText(userStory.getStartDate());
    	this.dueDate.setText(userStory.getDueDate());
    }
    
    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {
    	
    	UserStory userStory = new UserStory();
		userStory.setResponsible(this.jTextFieldName.getText());
		userStory.setBusinessValue(this.jTextFieldProgress.getText());
		if(!this.jTextFieldRole.getText().equals("")){
			userStory.setProgress(Integer.parseInt(this.jTextFieldRole.getText()));
		}
		userStory.setStartDate(this.startDate.getText());
		userStory.setDueDate(this.dueDate.getText());
	
    	if(mode == 1){
    	
    		
    	}else
    	{
    		
    		
    	}
    	closeDialog(null);
    	
    }
    
    private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {
        closeDialog(null);
    }
    
    /** Closes the dialog */
    private void closeDialog(WindowEvent evt) {
        setVisible(false);
        dispose();
    }
    
   
    private javax.swing.JButton btnClose;
    private javax.swing.JButton btnSave;
    
    private javax.swing.JLabel jLabelName;
	private javax.swing.JLabel jLabelRole;
	private javax.swing.JLabel jLabelStartDate;
	private javax.swing.JLabel jLabelDueDate;
	private javax.swing.JLabel jLabelProgress;
	
	
	private JFormattedTextField startDate;
	private JFormattedTextField dueDate;
	private javax.swing.JTextField jTextFieldRole;
	private javax.swing.JTextField jTextFieldName;
	private javax.swing.JTextField jTextFieldProgress;
	private DateFormat dateFormat;
   
}
